package com.buba1904.web;


import com.buba1904.entity.User;
import com.buba1904.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dxy
 * @since 2021-08-11
 */
@RestController
@RequestMapping("/user")
public class UserController {


    @Autowired
    private IUserService userService;

    @GetMapping("/list.json")
    public List<User> list() {
        return userService.list(null);
    }

    @DeleteMapping("/remove{id}")
    public boolean remove(@PathVariable Integer id) {
        boolean remove = userService.removeById(id);
        return remove ? true : false;
    }

    @GetMapping("/select{id}")
    public User user(@PathVariable Integer id){
        return userService.getBaseMapper().selectById(id);
    }

    @GetMapping("/update")
    public boolean update(User user) {
        boolean b = userService.updateById(user);
        return b ? true : false;
    }

    @GetMapping("/insert")
    public boolean insert(User user) {
        boolean b = userService.save(user);
        return b ? true : false;
    }


}
